package com.controller
{	
	import com.model.valueObjects.VOCountryCurrency;
	import com.model.valueObjects.VOCountryState;
	import com.service.CombinationMaster;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class CombinationMasterController extends AbstractController
	{
		import com.model.Model;
		
		[Inject]
		public var combinationMasterService:CombinationMaster;
		
		
		//[PostConstruct]
		public function CombinationMasterController()
		{
			super();	
		}
		
		[EventHandler(event="CombinationMasterEvent.GET_ALL")]
		public function getAll():void{
			sh.executeServiceCall(combinationMasterService.getAllCountryCurrency(),getAllResult, handleFault );
		}
		private function getAllResult(event:ResultEvent):void
		{
			model.countryCurrencyList=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;	
		}
		
		[EventHandler(event="CombinationMasterEvent.ADD", properties="countryCurrencyVo")]
		public function add(countryCurrencyVo:VOCountryCurrency):void
		{
			sh.executeServiceCall(combinationMasterService.addNewCountryCurrency(countryCurrencyVo), addResult, handleFault );	
		}
		private function addResult(event:ResultEvent):void
		{
			model.countryCurrencyList=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="CombinationMasterEvent.UPDATE", properties="countryCurrencyVo")]
		public function update(countryCurrencyVo:VOCountryCurrency):void
		{
			sh.executeServiceCall(combinationMasterService.editCountryCurrency(countryCurrencyVo), updateResult, handleFault );	
		}
		private function updateResult(event:ResultEvent):void
		{
			model.countryCurrencyList=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="CombinationMasterEvent.GET_STATES")]
		public function getStates():void{
			sh.executeServiceCall(combinationMasterService.getAllStates(),getStatesResult, handleFault );
		}
		private function getStatesResult(event:ResultEvent):void
		{
			model.stateMasterList=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;	
		}
		
		[EventHandler(event="CombinationMasterEvent.ADD_STATE", properties="countryStateVo")]
		public function addState(countryStateVo:VOCountryState):void
		{
			sh.executeServiceCall(combinationMasterService.addNewCountryState(countryStateVo), addStateResult, handleFault );	
		}
		private function addStateResult(event:ResultEvent):void
		{
			model.stateMasterList=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		[EventHandler(event="CombinationMasterEvent.UPDATE_STATE", properties="countryStateVo")]
		public function updateState(countryStateVo:VOCountryState):void
		{
			sh.executeServiceCall(combinationMasterService.editCountryState(countryStateVo), updateStateResult, handleFault );	
		}
		private function updateStateResult(event:ResultEvent):void
		{
			model.stateMasterList=event.result as ArrayCollection;
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		private function handleFault(event:FaultEvent):void
		{
			Alert.show( event.fault.faultDetail, "Error" );
		}
	}
}